import random
from socket import *
from dataStruct import quoteStruct as qStruct

def makeQuotes (min, max, symbol, count):
    
    quoteFeed = []
    while count !=0:
        quote = random.uniform(min,max)
        #side = buyOrSell()
        #quote = ('%.2f' % quote)
        side = random.randint(1,2)
        quote = (symbol, side, 100, quote)
        count -= 1
        
        quoteFeed.append(quote)
        #print quote
    return quoteFeed


def buyOrSell():
    side = random.randint(1,2)
    if side == 1:
        side = str('buy')
    else:
        side = str('sell')  
    return side



host = '224.0.0.1'
port = 12345
buff = 1024
addr = (host, port)
min = 290
max = 299
count = 100000
symbol = 'APPL'

quotes = makeQuotes(min, max, symbol, count)

UDPSock = socket(AF_INET,SOCK_DGRAM)
quoteObj = qStruct()
for quote in quotes:
    
    quoteObj.bufferValues(quote)
    UDPSock.sendto(quoteObj.buffer.raw,addr)
    print quoteObj.buffer.raw
    
    
    
UDPSock.close()
